<%@page import="java.util.ArrayList"%>
<%@page import="com.situ.web.entity.Banji"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.css"/>
</head>
<body>
	<body>
    <a href="<%=request.getContextPath() %>/banji_insert.jsp" class="btn btn-success">添加</a>
    <button  class="btn btn-success" onclick="selectCourse()">选课</button>
    <form action="<%=request.getContextPath() %>/banji?method=selectById" method="post" >
    	<input type="text" name="id">
    	<input type="submit" value="根据id查询" >
    </form><br> 
    <form action="<%=request.getContextPath() %>/banji?method=search" method="post" >
    	<input type="text" name="searchName">
    	<input type="submit" value="模糊查询" >
    </form><br>
	<table class="table table-striped table-bordered table-hover table-condensed">
		<tr>
			<td>ID</td>
			<td>班级名称</td>
			<td>课程名称</td>
			<td>课程学分</td>
			<td>删除</td>
			<!-- <td>修改</td> -->
		</tr>
		<c:forEach items="${list }" var="map">
			<tr>
				<td>${map["id"] }</td>
				<td>${map["name"] }</td>
				<td>${map["courseName"] }</td>
				<td>${map["credit"] }</td>
				<td><a href="javascript:void(0)" onclick="deleteById(${banji.id})">删除</a></td>
				<%-- <td><a href="javascript:void(0)" onclick="selectById(${banji.id})">修改</a></td> --%>
			</tr>
		</c:forEach>	
</body>
<div style="display:none" id="divId">
	<form id="ajax_form"  method="post" onsubmit="return false">
		<select id="selectBanjiId" name="banjiId">
			<option>---请选择---</option>
		</select>
		<select id="selectCourseId" name="courseId">
			<option>---请选择---</option>
		</select>
		<input type="button" onclick="submitForm()" class="btn btn-success" value="确认">
	</form>
</div>
<script src="js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
<script src="lib/layer/layer.js" type="text/javascript" charset="utf-8"></script>
<script src="lib/mylayer.js" type="text/javascript" charset="utf-8"></script>
<script src="lib/util.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	
	function submitForm(){
		$.ajax({
			url : "${pageContext.request.contextPath}/course?method=insertBanjiIdCourseId",
			type : "post",
			dataType : "json",
			data : $("#ajax_form").serialize(),
			success : function(jsonObj) {
				console.log(jsonObj);
				if(jsonObj.code == util.SUCCESS) {
					mylayer.successMsg(jsonObj.msg);
					//当你在iframe页面关闭自身时
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					setTimeout(function(){
						parent.layer.close(index); //再执行关闭 
						// 刷新父页面
						window.parent.location.reload();
					},1000);
				} else {
					mylayer.errorMsg(jsonObj.msg);
				}
				
			}
		});
	}
	
	
	function selectCourse(){
		console.log(123);
		
		
		layer.open({
			type:1,
			area:["200px","200px"],
			content:$("#divId")
		});
		
		
			$.post(
				"/JavaWeb1907/banji?method=selectById",
				function(jsonArray){
					console.log(jsonArray);
					$(jsonArray).each(function(){
						var html = "<option value='"+this.id+"'>"+this.name+"</option>";
						$("#selectBanjiId").append(html);
					});
				},
				"json"
		);
			$.post(
					"/JavaWeb1907/course?method=selectCourse",
					function(jsonArray){
						console.log(jsonArray);
						$(jsonArray).each(function(){
							var html = "<option value='"+this.id+"'>"+this.name+"</option>";
							$("#selectCourseId").append(html);
						});
					},
					"json"
			);
	}

	function deleteById(id){
		var isDel = confirm("您确定要删除吗？");
		if(isDel){
			location.href = "<%=request.getContextPath() %>/banji?method=deleteById&id="+id;
		}
	}
	
	function selectById(id){
		var isDel = confirm("您确定要修改吗？");
		if(isDel){
			location.href = "<%=request.getContextPath() %>/banji?method=selectById2&id="+id;
		}
	}
		
	</script>
</html>